#! /bin/bash

/export/server/presto/bin/presto --server hadoop01:8090 --catalog hive --schema default --execute \
" \
delete \
from hive.dm.year_sign; \
insert into hive.dm.year_sign \
select substring(day, 1, 4), \
       origin_type, \
       itcast_subject_id, \
       itcast_school_name, \
       itcast_subject_id, \
       itcast_subject_name, \
       origin_channel, \
       department_name, \
       sum(pay_count), \
       sum(relationship_count), \
       sum(valid_count), \
       group_type \
from hive.dws.day_sign \
group by substring(day, 1, 4), origin_type, itcast_school_id, itcast_school_name, itcast_subject_id, \
         itcast_subject_name, origin_channel, department_name, group_type; \
delete \
from hive.dm.month_sign; \
insert into hive.dm.month_sign \
select substring(day, 1, 7), \
       origin_type, \
       itcast_subject_id, \
       itcast_school_name, \
       itcast_subject_id, \
       itcast_subject_name, \
       origin_channel, \
       department_name, \
       sum(pay_count), \
       sum(relationship_count), \
       sum(valid_count), \
       group_type \
from hive.dws.day_sign \
group by substring(day, 1, 7), origin_type, itcast_school_id, itcast_school_name, itcast_subject_id, \
         itcast_subject_name, origin_channel, department_name, group_type; \
"